/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ihmproject.menuoutils;

import java.awt.event.ActionEvent;
import org.ihmproject.treewindow.FenetreArbreTopComponent;
import org.ihmproject.voletEdition.MyIconNodeWidget;
import org.ihmproject.voletEdition.MyNode.AddCookieImpl;
import org.ihmproject.voletEdition.MyNode.DeleteCookieImpl;
import org.openide.cookies.EditCookie;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import org.openide.windows.WindowManager;
import org.openide.windows.Mode;


public final class NouvelleTacheAction2 extends CookieAction {
    int i = 0;
    protected void performAction(Node[] activatedNodes) {
        AddCookieImpl editCookie = activatedNodes[0].getLookup().lookup(AddCookieImpl.class);
        Mode mod = WindowManager.getDefault().findMode(FenetreArbreTopComponent.findInstance());
        FenetreArbreTopComponent fatc = (FenetreArbreTopComponent) mod.getSelectedTopComponent();

        if (fatc.scene.getSelectedObjects().toArray().length > 0) {
            SpecificationTacheWizardAction st = new SpecificationTacheWizardAction();
            st.actionPerformed(null);
            //System.out.println((String)st.operateur);
            //System.out.println((String)st.categorie);
            //System.out.println((String)st.pcond);
            //System.out.println(st.deco.size());
            //System.out.println(st.pforme);
            MyIconNodeWidget parent = (MyIconNodeWidget) fatc.scene.findWidget(fatc.scene.getSelectedObjects().toArray()[0]);
            MyIconNodeWidget ajout = (MyIconNodeWidget)fatc.addNode(st.lenom+i,st.lenom, ((String)fatc.scene.getSelectedObjects().toArray()[0]),""+i, (String)st.categorie,st.pforme,st.deco,(String)st.pcond, (String) st.operateur, parent);
            parent.addChild(ajout);
            i++;

            if (parent.getChilds().size() > 1) {
                ajout.setIDEgdeOp("test"+i);
                fatc.addOperator("test"+i , "test",  parent.getChilds().get(parent.getChilds().size()-2).getID(), ajout.getID());
                ajout.majOP();
                i++;
            }
            fatc.scene.validate();

        }
    }

    protected int mode() {
        return CookieAction.MODE_EXACTLY_ONE;
    }

    public String getName() {
        return NbBundle.getMessage(NouvelleTacheAction2.class, "CTL_NouvelleTacheAction2");
    }

    protected Class[] cookieClasses() {
        return new Class[]{AddCookieImpl.class};
    }

    @Override
    protected String iconResource() {
        return "org/ihmproject/menuoutils/db_add_24.png";
    }

    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous() {
        return false;
    }
}

